# coding=utf-8
import sys
from function_utils import Global, Common


def execute_cmd():
    try:
        cmd = Global.values_parse(sys.argv[2])[1]['Text']
        ret, out, err = Common.execute_cmd(cmd)
    except Exception as e:
        print(str(e))
        return False, ''
    if not ret:
        print(err)
    return True, out


def write_widgets_value(result):
    state, value = result
    data = [
        {},
        {},
        {"MultiInfoText": value}
    ]
    Global.values_write(data)
    if state:
        Global.report_info(100)
    else:
        Global.report_err(100)


def main():
    if sys.argv[1] == 'start':
        write_widgets_value(execute_cmd())


if __name__ == '__main__':
    main()
